﻿using System;

using Sunyi.Project.WebPoint.DataContract;
using Sunyi.Project.WebPoint.ServiceContract;

namespace Sunyi.Project.WebPoint.ServiceAccess
{
    public class SecurityTokenServiceProxy : WebPointServiceProxy<ISecurityTokenService>, ISecurityTokenService
    {
        protected override string ClientEndPointName
        {
            get
            {
                return "SecurityTokenService";
            }
        }

        public Token IssueToken(string userName, string password)
        {
            Token result = null;
            var channel = this.CreateChannel();

            var action = new Action(delegate { result = channel.IssueToken(userName, password); });

            this.Invoke(channel, action);
            return result;
        }

        public Token GetToken(Guid id, string accessCode)
        {
            Token result = null;
            var channel = this.CreateChannel();

            var action = new Action(delegate { result = channel.GetToken(id, accessCode); });

            this.Invoke(channel, action);
            return result;
        }

        public void RemoveToken(Guid id, string accessCode)
        {
            var channel = this.CreateChannel();

            var action = new Action(delegate { channel.RemoveToken(id, accessCode); });

            this.Invoke(channel, action);
        }

        public bool VerifyAccessCode(string userName, string accessCode)
        {
            bool result = false;
            var channel = this.CreateChannel();

            var action = new Action(delegate { result = channel.VerifyAccessCode(userName, accessCode); });

            this.Invoke(channel, action);
            return result;
        }
    }
}
